package cn.wolfcode.luowowo2;

import cn.wolfcode.luowowo2.member.config.MemberConfig;
import cn.wolfcode.luowowo2.website.web.interceptor.CheckLoginInterceptor;
import cn.wolfcode.luowowo2.website.web.param.UserInfoArgumentResolver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * Created by Albert on 2019/7/5.
 */
@SpringBootApplication
public class WebSiteApplication implements WebMvcConfigurer{

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/userLogin")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/userRegist")
                ;
       /* .excludePathPatterns("/css*//**")
                .excludePathPatterns("/images*//**")
                .excludePathPatterns("/js*//**")*/
    }

    @Bean
    public CheckLoginInterceptor checkLoginInterceptor(){
        return new CheckLoginInterceptor();
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userInfoArgumentResolver());
    }


    @Bean
    public UserInfoArgumentResolver userInfoArgumentResolver(){
        return new UserInfoArgumentResolver();
    }

    public static void main(String[] args) {
        System.setProperty("es.set.netty.runtime.available.processors","false");
        SpringApplication.run(WebSiteApplication.class,args);
    }
}
